package com.agilerabbit.tools;


import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;


public class ObjectSerialiser {

	public static byte[] serializeObject(Object o) {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

		try {
			ObjectOutput out = new ObjectOutputStream(outputStream);
			out.writeObject(o);
			out.close();			
			byte[] buf = outputStream.toByteArray();

			return buf;
		} catch (IOException ex) {		

			return null;
		}
	}

	public static Object deserializeObject(byte[] b) {
		try {
			ObjectInputStream inputStream = new ObjectInputStream(
					new ByteArrayInputStream(b));
			Object object = inputStream.readObject();
			inputStream.close();

			return object;
		} catch (ClassNotFoundException ex) {			

			return null;
		} catch (IOException ex) {
			

			return null;
		}
	}

}
